package zdream.control.foe.mm5bbitter;

import zdream.control.world.buff.AttackModule;
import zdream.control.world.buff.HealthModule;
import zdream.control.world.MFoe;
import zdream.control.world.MHookType;
import zdream.control.world.TerrainHandler;

import static zdream.control.world.MFoeConstants.*;

/**
 * @author Zdream
 * @since 0.0.1
 * @date 2022-06-10 (created)
 */
public class MM5BBitterBullet extends MFoe {
	public static final String NAME = "MM5BBitterBullet";

	public MM5BBitterBullet(MFoe parent) {
		super(parent.world);
		this.type = TYPE_BULLET;
		this.side = parent.side;
	}

	@Override
	public String foeName() {
		return NAME;
	}

	@Override
	public void init() {
		createNormalPattern()
				.withRectangle(-1/6f, -1/6f, 1/3f, 1/3f)
				.apply();

		attackModule = buildAttackModule()
				.damage(4)
				.damageLevel(DAMAGE_LEVEL_BULLET)
				.ignoreSide(side)
				.targetTypesIsEntity()
				.stopAfterAttackOnce()
				.destroyAfterAttackReceived()
				.create();
		healthModule = buildHealthModule()
				.maxAgeInMS(3000)
				.create();

		terrainHandler = new TerrainHandler(world);
		terrainHandler.floating = true;

		onHook(MHookType.TICK)
				.handle(this::move)
				.buildAndSave();
	}
	public HealthModule healthModule;
	public AttackModule attackModule;

	/**
	 * 横向速度, 是个定值, 单位: p/s
	 */
	public float vx;

	public MM5BBitterBullet setVelocity(float vx) {
		this.vx = vx;
		return this;
	}

	public void move() {
		setVelocity(vx * world.ticker.duration, 0);
		terrainHandler.submitFloatBoxMotion(this);
	}
}
